<template>
	<view class="u-page" >
		<up-list>
			
			<up-list-item
				v-for="(item, index) in myArtData"
				:key="index"
			>
			
				<up-cell
				:value="getTimeDiff(item.posttime)"
				:title="item.content"
					@click="detailArt(item._id)"
				>
					<template #icon>
						<up-avatar
							shape="square"
							size="35"
							:src="item.userid[0].avatar_file.url"
							customStyle="margin: -3px 5px -3px 0"
						></up-avatar>
					</template>
				</up-cell>
			</up-list-item>
		</up-list>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app'
import { getTimeDiff } from "@/utils/commen.js"
const myArtData = ref([])
const db = uniCloud.database()
let artTemp = db.collection('articles').field("content,imageValue,userid,posttime").getTemp();
let usetTemp = db.collection('uni-id-users').field("_id,username,avatar_file").getTemp()
db.collection(artTemp,usetTemp).where('userid._id == $cloudEnv_uid').orderBy('posttime desc,_id desc') .get().then(res=>{
	myArtData.value = res.result.data
}).catch(err=>{
	if(err == 'Error: 未能获取当前用户信息：当前用户为匿名身份'){
		uni.showModal({
			content:'未登录，请重新登入',
			title:'提示',
			success: (res) => {
				if(res.confirm)
				
				uni.navigateTo({
					url:"/uni_modules/uni-id-pages/pages/login/login-withpwd"
				})
			}
		})
	}
	
})
onLoad(()=>{

})



// updateArt
const detailArt = (id) =>{
	uni.navigateTo({
		url:"/pages/detail/index?id="+id
	})
}
</script>

<style lang="scss">
	
</style>